<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="cpNav"
      />
    </div>

    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="cpPropRules" ref="editForm" :disabled="propReadonly" :labelWidth="120">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="商品分类" name="baseType" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name" :config="{dictType: constCommon.dictType.baseMatrType}"
                          helpTip="根据实际情况选择<br>不同分类的属性选项是不一样的"
                          ref="baseType"
                          @change="baseTypeChange"

          />
          <customFormItem label="商品名称" name="name" :parent="_self" :form="form" width2x/>
          <customFormItem label="商品规格" name="spec" :parent="_self" :form="form" />

          <!--医疗用品专属属性-->
          <customFormItem
            label="供方名称" name="supplierName" :parent="_self" :form="form"
            @focusTo="$refs.supplierName.focus()"
            :type="form.flagDisabledSpEdit ? constCommon.formItemType.inputText.name : constCommon.formItemType.slot.name "
            width2x
            help-tip="商品做了外网映射或者存在相关出入库记录后<br>不允许修改所属供应商"
            :disabled="form.flagDisabledSpEdit"
          >
            <template #content>
              <spSelect
                v-model="form.supplierId"
                :valueDisplay="form.supplierName"
                @change="spSelect"
                :disabled="propReadonly"
                ref="supplierName"
                :popWidth="440"
              />
              <customButton
                title="+"
                help="列表不存在供应商时，可以新增供应商"
                theme="primary"
                size="small"
                @click="utilSelect.openSelectCreateFormSp(spSelect)"
                v-show="!propReadonly"
                style="font-size: 20px; width: 20px;position: absolute;right: -22px;"
              >
              </customButton>
            </template>
          </customFormItem>

          <customFormItem
            label="生产厂商" name="mfgName" :parent="_self" :form="form"
            @focusTo="$refs.mfgName.focus()"
            :type="constCommon.formItemType.slot.name"
            width2x
          >
            <template #content>
              <mfgSelect
                v-model="form.mfgId"
                :valueDisplay="form.mfgName"
                @change="mfgSelect"
                :disabled="propReadonly"
                ref="mfgName"
                :popWidth="440"
              />
              <customButton
                title="+"
                help="列表不存在厂商时，可以新增厂商"
                theme="primary"
                size="small"
                @click="utilSelect.openSelectCreateFormMfg(mfgSelect)"
                v-show="!propReadonly"
                style="font-size: 20px; width: 20px;position: absolute;right: -22px;"
              >
              </customButton>
            </template>
          </customFormItem>

          <customFormItem label="单品单位" name="skuUnit" :parent="_self" :form="form"
                          helpTip="修改后将同步更新到单品单位里面"
          />
          <customFormItem label="单品价格" name="skuPrice" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name"
                          helpTip="修改后将同步更新到单品单位里面"
          />

          <customFormItem
            label="管理分类"
            name="categoryName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="$refs.tableDrawerCategory.show()"
          />

          <customFormItem label="型号" name="model" :parent="_self" :form="form" />

          <customFormItem label="商品检索码" name="namePy" :parent="_self" :form="form" disabled help-tip="自动生成" />
          <customFormItem label="备注" name="remark" :parent="_self" :form="form" full-width/>

          <!--医疗用品专属属性-->
          <div id="box-med" class="box-title" v-show="utils.isBaseTypeMed(form.baseType)">医疗用品属性</div>
          <div v-show="utils.isBaseTypeMed(form.baseType)">
            <customFormItem label="注册证号" name="certificateNo" :parent="_self" :form="form" />
            <customFormItem label="注册证开始" name="certificateBegin" :parent="_self" :form="form" :type="constCommon.formItemType.datePicker.name" />
            <customFormItem label="注册证截止" name="certificateExp" :parent="_self" :form="form" :type="constCommon.formItemType.datePicker.name"
                            help-tip="如果长期，请指定为2099-01-01"
            />
            <customFormItem label="中标号" name="bidno" :parent="_self" :form="form"/>
            <customFormItem label="UDI-DI" name="udi" :parent="_self" :form="form"/>
            <customFormItem label="标签类型" name="labelType" :parent="_self" :form="form" :type="constCommon.formItemType.selectDict.name"
                            :config="{dictType: constCommon.dictType.labelType}"
                            help-tip="外部打印标签码时使用"
            />
            <customFormItem label="采购类型" name="purchaseType" :parent="_self" :form="form" :type="constCommon.formItemType.selectDict.name" :config="{dictType: constCommon.dictType.purchaseType}"/>
            <customFormItem label="带量采购类型" name="matrQbtCode" :parent="_self" :form="form"
                            :type="constCommon.formItemType.selectStatic.name"
                            :config="{options: matrQbtCodeList, label: 'typeName',labelShow: 'typeName', value: 'typeCode'}"
            />
            <!--试剂专属属性-->
            <customFormItem label="存储温度" name="temperature" :parent="_self" :form="form"
                            :type="constCommon.formItemType.inputNumber.name"  v-show="cpIsReagent"/>
            <customFormItem label="人份" name="personPortion" :parent="_self" :form="form"
                            :type="constCommon.formItemType.inputNumber.name"  v-show="cpIsReagent"/>
          </div>

          <div id="box-unit" class="box-title">单位信息</div>
          <data-view
                     propViewKey="base_matr_unit"
                     propViewForm="base/material/matr-unit/detail.vue"
                     :propInitData="form"
                     ref="childDataView"
                     :propsDisableDbClick="true"
                     :propHidePageSearch="true"
                     :propHideQueryButton="true"
                     :propParentPage="_self" :propAutoFetchData="false"
                     :propOnlyQueryAll="propReadonly"
                     :propTableHide="propParent.cpFormNew"
                     propTableHideMsg="请先保存商品信息后再维护单位"
          />

          <div id="box-status" class="box-title">状态信息</div>
          <!--非医疗用品属性-->
          <div v-show="!utils.isBaseTypeMed(form.baseType)">
            <customFormItem label="是否禁用" name="flagDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="禁用后该商品不可使用"
            />
            <customFormItem label="是否寄售" name="flagConsignment" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="寄售：用后结算，非寄售：入库结算"
                            disabled
            />
            <customFormItem label="是常备耗材" name="flagCenterPurchase" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="是：中心仓库备货，否：科室专购品"
                            disabled
            />
            <customFormItem label="数量化管理" name="flagMagnum" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="开启后，该商品入库出库支持数量化操作，库存以商品id+批号累加<br>只有【非标签管理】的支持数量化操作"
                            disabled
            />
          </div>
          <!--医疗用品专属属性-->
          <div v-show="utils.isBaseTypeMed(form.baseType)">
            <customFormItem label="是否禁用" name="flagDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="禁用后该商品不可使用"
            />
            <customFormItem label="标签管理" name="flagOmoc" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            @change="flagOmocChange"
                            help-tip="需要通过HIS进行扫码收费的商品"
            />
            <customFormItem label="是否寄售" name="flagConsignment" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="寄售：用后结算，非寄售：入库结算"
                            :disabled="form.flagOmoc"
            />
            <customFormItem label="是常备耗材" name="flagCenterPurchase" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="是：中心仓库备货，否：科室专购品"
            />
            <customFormItem label="数量化管理" name="flagMagnum" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="开启后，该商品入库出库支持数量化操作，库存以商品id+批号累加<br>只有【非标签管理】的支持数量化操作"
                            :disabled="form.flagOmoc"
            />

            <customFormItem label="是否库存试剂" name="flagStockReagent" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />

            <customFormItem label="是否高耗" name="flagHigh" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="是否临采" name="flagTemporaryPurchase" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="是否防疫" name="flagPlagueMatr" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />

            <customFormItem label="是否植入耗材" name="flagImplantation" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="是否介入耗材" name="flagInterventional" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="是否进口" name="flagImported" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="是否集采" name="flagPurcenter" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="是否重点监控" name="flagMonitor" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
          </div>


          <!--医疗用品专属属性-->
          <div v-show="utils.isBaseTypeMed(form.baseType)">
            <div id="box-sp" class="box-title">外网信息</div>
            <customFormItem label="外网编码" name="mscmCode" :parent="_self" :form="form" disabled
                            help-tip="供应商平台对应的商品编码"
            />
            <customFormItem label="资质禁用" name="mscmDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"  disabled/>
            <customFormItem label="资质禁用说明" name="mscmDisabledDesc" :parent="_self" :form="form"  disabled/>

            <div id="box-his" class="box-title">HIS信息</div>
            <customFormItem
              label="HIS编码"
              name="hisCode"
              :parent="_self"
              :form="form"
              :readonly="true"
              :showSelectIcon="true"
              @focus="$refs.tableDrawerHisCode.show()"
              help-tip="对应的是HIS收费项目编码"
            />
            <customFormItem label="HIS名称" name="hisName" :parent="_self" :form="form" help-tip="对应的是HIS收费项目名称"/>
            <customFormItem label="HIS价格" name="hisPrice" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name"
                            help-tip="对应的是HIS收费项目价格，因为0加成的影响，一般商品单品价格和HIS收费项目价格是一样的"
            />
            <customFormItem label="可收费" name="hisFlagCharge" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"
                            help-tip="该属性暂无特殊逻辑处理"
            />
            <customFormItem label="HIS禁用" name="hisDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>

            <div id="box-yb" class="box-title">医保信息</div>
            <customFormItem label="医保代码27位" name="hisMedicareNo2" :parent="_self" :form="form" width2x
                            help-tip="指定后，将根据医保代码自动匹配填充该商品的HIS收费项目信息"
            />
            <customFormItem label="医保名称27位" name="hisMedicareName2" :parent="_self" :form="form" width2x/>
            <customFormItem label="医保代码20位" name="hisMedicareNo" :parent="_self" :form="form" width2x/>
            <customFormItem label="医保名称20位" name="hisMedicareName" :parent="_self" :form="form" width2x/>

            <div id="box-hrp" class="box-title">HRP信息<small class="span-msg-nopad" style="margin-left: 10px">新增商品HRP属性不指定将默认与商品基础属性保持一致</small></div>
            <customFormItem label="HRP名称" name="hrpName" :parent="_self" :form="form" />
            <customFormItem label="HRP编码" name="hrpCode" :parent="_self" :form="form" />
            <customFormItem label="HRP品规" name="hrpSpec" :parent="_self" :form="form" />
            <customFormItem label="HRP单位" name="hrpUnit" :parent="_self" :form="form" />
            <customFormItem label="HRP厂商" name="hrpMfg" :parent="_self" :form="form" />
            <customFormItem label="禁用状态" name="hrpDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
            <customFormItem label="财务禁用状态" name="hrpFinanceDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>

            <div id="box-sun" class="box-title">阳采信息</div>
            <customFormItem label="阳采产品ID" name="sunGoodsID" :parent="_self" :form="form"/>
            <customFormItem label="阳采产品编号" name="sunSubcodeId" :parent="_self" :form="form"/>
            <customFormItem label="阳采品名" name="sunGoodsName" :parent="_self" :form="form"/>
            <customFormItem label="阳采规格编号" name="sunOutlookc" :parent="_self" :form="form"/>
            <customFormItem label="阳采型号" name="sunGoodtype" :parent="_self" :form="form"/>
            <customFormItem label="阳采分类" name="sunSortName" :parent="_self" :form="form"/>
            <customFormItem label="阳采单位" name="sunUnit" :parent="_self" :form="form"/>
            <customFormItem label="是阳光采购" name="flagSunpurchase" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
            <customFormItem label="阳光采购指标" name="skuQtySunpurchase" :parent="_self" :form="form"  :type="constCommon.formItemType.inputNumber.name"/>
            <customFormItem label="阳光采购代码" name="sunpurchaseCode" :parent="_self" :form="form"/>
          </div>

          <div id="box-img" class="box-title">商品图片</div>
          <customFormItem
            label=""
            name="matrImg"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.slot.name"
            fullWidth
          >
            <template #content>
              <customUpload
                :data="{ fileRefId: form.id, fileRefTable: 'base_matr', fileSavePath: 'base_matr'}"
                :hide="strings.isBlank(form.id)"
                hideMsg="请先保存耗材后再上传"
                :max="20"
                :disabled="propReadonly"
                multiple
              />
            </template>
          </customFormItem>
        </template>
      </customForm>
    </div>

    <!--分类选择-->
    <tableDrawer ref="tableDrawerCategory" refName="tableDrawerCategory" @confirm="tableDrawerConfirm" :viewKey="constCommon.viewKeySelect.matrCategory"/>

    <!--his编码选择-->
    <tableDrawer ref="tableDrawerHisCode" refName="tableDrawerHisCode" @confirm="tableDrawerConfirm" :viewKey="constCommon.viewKeySelect.matrHis"/>
  </div>
</template>

<script>
import FortenUpload from '@/components/common/FortenUpload.vue'
import SupplierSelect from '@/components/base/SupplierSelect'
import sunMenu from '@/views/sunMenu/sun_menu.vue'
import customAnchor from '@/components/custom/form/customAnchor.vue'
import customUpload from '@/components/custom/form/customUpload.vue'
import spSelect from '@/components/custom/bus/select/spSelect.vue'
import mfgSelect from '@/components/custom/bus/select/mfgSelect.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {},
      selectSupplierColumns: [
        { name: 'name', span: 20, search: true  },
        { name: 'namePy', span: 4, search: true  },
      ],
      selectMfgColumns: [
        { name: 'name', span: 20, search: true  },
        { name: 'namePy', span: 4, search: true  },
      ],
      activeNames: ['1', '2', '12', '4', '5', '6'],
      dialogShow: false, //是否显示阳采选择框
      matrQbtCodeList: []
    }
  },
  filters: {
    filterImage(data) {
      return `${data}?temp=${Math.random()}`
    }
  },
  methods: {
    getChildViewQueryWrapper() {
      if (this.form.id) {
        return this.$newWrapper().eq('matrId', this.form.id)
      } else {
        return this.$newWrapper().ne('1', 1)
      }
    },
    getChildRows() {
      if (!this.$refs.childDataView) {
        return []
      }
      return this.$refs.childDataView.getRows0()
    },

    //弹框选择耗材
    selectChangeWin(row) {
      this.$set(this.form, 'sunGoodsID', row.sunGoodsId)
      this.$set(this.form, 'sunSortName', row.sunSortName)
      this.$set(this.form, 'sunGoodsName', row.sunGoodsName)
      this.$set(this.form, 'sunUnit', row.sunUnit)
      this.$set(this.form, 'sunSubcodeId', row.sunSubcodeId)
      this.$set(this.form, 'sunOutlookc', row.sunOutlookc)
      this.$set(this.form, 'sunGoodtype', row.sunGoodtype)
    },
    //显示阳采耗材
    showWin() {
      console.log('跳转')
      this.dialogShow = true
      this.$nextTick(() => {
        this.$refs.sunMenu.resetForm()
      })
    },

    //下拉列表选择后
    selectChange({fieldText, row}) {
      if (fieldText == 'supplierName') { //选择完供应商
        this.$set(this.form, 'supplierId', row.id)
        this.$set(this.form, 'supplierName', row.name)
      } else  if (fieldText == 'mfgName') { //选择完厂商
        this.$set(this.form, 'mfgId', row.id)
        this.$set(this.form, 'mfgName', row.name)
      } else  if (fieldText == 'categoryName') { //选择分类
        this.$set(this.form, 'categoryId', row.id)
        this.$set(this.form, 'categoryName', row.categoryName)
      } else if  (fieldText == 'hisCode') {
        this.$set(this.form, 'hisCode', row.hisCode)
        this.$set(this.form, 'hisName', row.name)
        this.$set(this.form, 'hisDisabled', row.flagDisabled)
        this.$set(this.form, 'hisPrice', row.pricePatientAdult)
      }
    },

    handleUploadSuccess(res, file) {
      if (res.success) {
        this.$set(this.form, 'imageUrl', res.data.url)
        this.$set(this.form, 'thumbnailImageUrl', '')
        this.$nextTick(() => {
          this.$set(this.form, 'thumbnailImageUrl', res.data.thumbnailUrl)
        })
        this.$forceUpdate()
      } else {
        this.utilMessage.error(`上传文件返回错误：${res.msg}`)
      }
    },
    handleBeforeUpload(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!isJPG) {
        this.utilMessage.error('上传头像图片只能是 JPG/PNG 格式!')
      }
      if (!isLt2M) {
        this.utilMessage.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },

    baseTypeChange() {
      if (this.form.baseType != 'reagent') {
        this.$set(this.form, 'temperature',  '无')
      }
      console.log('this.form.baseType= ' + this.form.baseType)
    },

    // 弹框选择
    tableDrawerConfirm(row, refName) {
      console.log('row, refName', row, refName)
      //供应商选择
      if (refName == 'tableDrawerSupplier') {
        this.spSelect(row)
        return true
      }

      //厂商选择
      if (refName == 'tableDrawerMfg') {
        this.mfgSelect(row)
        return true
      }

      //分类选择
      if (refName == 'tableDrawerCategory') {
        this.$set(this.form, 'categoryId', row.id)
        this.$set(this.form, 'categoryName', row.categoryName)
        return true
      }

      //his编码选择
      if (refName == 'tableDrawerHisCode') {
        this.$set(this.form, 'hisCode', row.hisCode)
        this.$set(this.form, 'hisName', row.name)
        this.$set(this.form, 'hisDisabled', row.flagDisabled)
        this.$set(this.form, 'hisPrice', row.pricePatientAdult)
        return true
      }
    },

    mfgSelect(row) {
      this.$set(this.form, 'mfgId', row.id)
      this.$set(this.form, 'mfgName', row.name)
    },

    spSelect(row) {
      this.$set(this.form, 'supplierId', row.id)
      this.$set(this.form, 'supplierName', row.name)
    },

    // 获取会计期间列表
    getMatrQbtCodeList() {
      let wrapper = this.$newWrapper()
      wrapper.orderConditions.push({ field: 'gmtCreate', rule: 'desc' })
      let params = {
        queryString: JSON.stringify(wrapper.queryConditions),
        orderString: JSON.stringify(wrapper.orderConditions)
      }
      this.$ajax.get('/base/matr_qbt/list', {params}).then(resp => {
        console.log('resp', resp)
        if (resp.data) {
          resp.data.forEach(item => {
            item.textShow = `<strong style="display: inline-block;width: 80px;">${item.typeCode}</strong><small>(${item.typeName})</small>`
          })
          this.matrQbtCodeList = resp.data
        }
      })
    },
    // 标签管理属性改变后
    flagOmocChange() {
      if (this.form.flagOmoc) {
        this.$set(this.form, 'flagMagnum', false)
        this.$set(this.form, 'flagConsignment', true)
      }
    }
  },
  created() {
    let that = this
    this.getMatrQbtCodeList()
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$set(this.form, 'isEdit', 1)

        if (this.utils.isBaseTypeLom(this.form.baseType)) {
          this.$set(this.form, 'flagMagnum', true)
          this.$set(this.form, 'flagConsignment', false)
          this.$set(this.form, 'flagOmoc', false)
          this.$set(this.form, 'flagCenterPurchase', true)
        }

        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.$set(this.form, 'flagDisabled', this.form.flagDisabled == undefined ? false : this.form.flagDisabled)
        this.$set(this.form, 'flagConsignment', this.form.flagConsignment == undefined ? false : this.form.flagConsignment)
        this.$set(this.form, 'flagOmoc', this.form.flagOmoc == undefined ? false : this.form.flagOmoc)
        this.$set(this.form, 'flagHigh', this.form.flagHigh == undefined ? false : this.form.flagHigh)
        this.$set(this.form, 'hisDisabled', this.form.hisDisabled == undefined ? false : this.form.hisDisabled)
        this.$set(this.form, 'mscmDisabled', this.form.mscmDisabled == undefined ? false : this.form.mscmDisabled)
        this.$set(this.form, 'hrpDisabled', this.form.hrpDisabled == undefined ? false : this.form.hrpDisabled)
        this.$set(this.form, 'hrpFinanceDisabled', this.form.hrpFinanceDisabled == undefined ? false : this.form.hrpFinanceDisabled)
        this.$set(this.form, 'hisFlagCharge', this.form.hisFlagCharge == undefined ? false : this.form.hisFlagCharge)
        this.$set(this.form, 'flagSunpurchase', this.form.flagSunpurchase == undefined ? false : this.form.flagSunpurchase)
        this.$set(this.form, 'flagCenterPurchase', this.form.flagCenterPurchase == undefined ? false : this.form.flagCenterPurchase)
        if (formData.id) {
        } else {
          this.$nextTick(() => {
            this.$refs.baseType.focus()
          })
        }
        if (this.propStatus == 'addnew') {
          this.$set(this.form, 'categoryId', 0)
          this.$set(this.form, 'flagDisabledSpEdit', false)
          //耗材分类
          // this.$set(this.form, 'baseType', this.utils.getMtrBaseType(this))

        }

        let wrapper = this.getChildViewQueryWrapper()
        this.$refs.childDataView.setQueryWrapper(wrapper)
        /*eslint-disable 下面赋值操作文件上传组件必须*/
        // this.$set(this.form, 'id', this.form.id)
      },
      afterSave: () => {
        this.utils.refreshRefs(this)
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      },
      async afterClick(button, data, viewForm) {
        let {key: buttonKey} = button
        if (buttonKey == 'pushOnce') {
          that.utilMessage.confirm('是否推送该耗材到供应商平台', () => {
            that.utilVue.loadShow(true)
            let idList =  new Array(that.form.id)
            that.$ajax.post('base/matr/getOnceMatrMscm', idList)
              .then(response => {
                that.utilVue.loadHide()
                if (response.code == 0) {
                  that.propParent.ocRefreshCurrentRow()
                  that.utilMessage.success(response.msg)
                } else {
                  that.utilMessage.error(response.msg)
                }
              })
          })

        }
        if (buttonKey == 'copyMatr') {
          that.utilMessage.confirm('是否复制该商品?', () => {
            that.utilVue.loadShow(true)
            that.$ajax.post('base/matr/copyMatr', {id: that.form.id})
              .then(response => {
                that.utilVue.loadHide()
                if (response.success) {
                  that.$confirm('复制成功，是否打开进行编辑?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                  }).then(() => {
                    that.propParent.viewRowOne(response.data.id)
                  }).catch(() => {
                  })
                }
              })
          })
        }
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
    propParam: Object
  },
  components: {  FortenUpload, SupplierSelect, sunMenu, customAnchor, customUpload,spSelect, mfgSelect},
  computed: {
    // 是否试剂
    cpIsReagent() {
      return this.constCommon.dictType.baseMatrTypeReagent.includes(this.form.baseType)
    },
    cpNav() {
      if (this.utils.isBaseTypeMed(this.form.baseType)) {
        return [
          { name: 'box-base', title: '基础信息' },
          { name: 'box-med', title: '医疗用品属性' },
          { name: 'box-unit', title: '单位信息' },
          { name: 'box-status', title: '状态信息' },
          { name: 'box-sp', title: '外网信息' },
          { name: 'box-his', title: 'HIS信息' },
          { name: 'box-yb', title: '医保信息' },
          { name: 'box-hrp', title: 'HRP信息' },
          { name: 'box-sun', title: '阳采信息' },
          { name: 'box-img', title: '商品图片' },
        ]
      }
      return [
        { name: 'box-base', title: '基础信息' },
        { name: 'box-unit', title: '单位信息' },
        { name: 'box-status', title: '状态信息' },
        { name: 'box-img', title: '商品图片' },
      ]
    },

    cpPropRules() {
      let rule = this.propRules
      // if (this.utils.isBaseTypeMed(this.form.baseType)) {
      //   rule.supplierName = [{ required: true, message: '必填', trigger: 'blur' }]
      //   rule.mfgName = [{ required: true, message: '必填', trigger: 'blur' }]
      // } else {
      //   rule.supplierName = []
      //   rule.mfgName = []
      // }
      return rule
    },
    cpIsBaseTypeMed() {
      return this.utils.isBaseTypeMed(this.form.baseType)
    }
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
<style lang="scss" scopped>
  .container {
    width: 100%;
    height: 100%;
  }
  .ext-select-example {
    width: 500px !important;
  }

</style>
